home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Metrowerks Versions / C07 QuickTime Movies / P04 Quick Controller / QuickController.c next >
Encoding:
C/C++ Source or Header  |  1995-08-05  |  3.1 KB  |  122 lines  |  [TEXT/MMCC]

  1. //____________________________________________________________
  2. //    QuickController.c
  3. //
  4. //    Copyright © Dan Parks Sydow, 1995
  5. //    From the book:
  6. //    "Graphics and Sound Programming Techniques for the Mac",
  7. //    M&T Books, 1995
  8.  
  9.  
  10. //____________________________________________________________
  11.  
  12. #include <Movies.h>   
  13. #include <Gestalt.h>
  14.  
  15.  
  16. //____________________________________________________________
  17.  
  18. void  InitializeAllToolboxes( void );
  19.  
  20.  
  21. //____________________________________________________________
  22.  
  23. #define      rMovieWindow           128
  24. #define      kMovieName        "\pRobot"
  25.  
  26.  
  27. //____________________________________________________________
  28.  
  29. void  main( void )
  30.    OSErr            theError;
  31.    FSSpec           theFSSpec;
  32.    short            theFileRefNum;
  33.    Movie            theMovie;
  34.    short            theMovieResID = 0;   
  35.    Str255           theMovieResName;
  36.    Boolean          wasAltered;
  37.    WindowPtr        theWindow;
  38.    Rect             theMovieBox;
  39.    Rect             theBoundsRect;
  40.    MovieController  theController = nil;
  41.    EventRecord      theEvent;
  42.    Boolean          isControllerEvent;
  43.    Boolean          allDone = false;
  44.  
  45.    InitializeAllToolboxes();
  46.    
  47.    theError = FSMakeFSSpec( 0, 0, kMovieName, &theFSSpec );
  48.    theError = OpenMovieFile( &theFSSpec, &theFileRefNum, fsRdPerm );
  49.    theError = NewMovieFromFile( &theMovie, theFileRefNum, &theMovieResID,
  50.                                  theMovieResName, newMovieActive, &wasAltered );
  51.                                          
  52.    CloseMovieFile( theFileRefNum );
  53.    
  54.    theWindow = GetNewCWindow( rMovieWindow, nil, (WindowPtr)-1L );   
  55.  
  56.    SetMovieGWorld( theMovie, (CGrafPtr)theWindow, nil );   
  57.  
  58.    GetMovieBox( theMovie, &theMovieBox );
  59.  
  60.    theController = NewMovieController( theMovie, &theMovieBox, mcTopLeftMovie);   
  61.  
  62.    MCGetControllerBoundsRect( theController, &theBoundsRect );
  63.  
  64.    SizeWindow( theWindow, theBoundsRect.right, theBoundsRect.bottom, true );  
  65.    ShowWindow( theWindow );
  66.  
  67.    while ( allDone == false )
  68.    {
  69.       WaitNextEvent( everyEvent, &theEvent, 15L, nil );
  70.       
  71.       if ( theController == nil )
  72.          isControllerEvent = false;
  73.       else
  74.          isControllerEvent = MCIsPlayerEvent( theController, &theEvent );
  75.       
  76.       if ( isControllerEvent == false )
  77.       {
  78.          switch ( theEvent.what )
  79.          {
  80.             case keyDown:
  81.                allDone = true;
  82.                break;
  83.          }
  84.       }
  85.    }
  86.  
  87.    DisposeMovieController( theController );
  88.    theController = nil;
  89.    DisposeMovie( theMovie );
  90.    DisposeWindow( theWindow );
  91. }
  92.  
  93.  
  94. //____________________________________________________________
  95.  
  96. void  InitializeAllToolboxes( void )
  97. {
  98.    OSErr  theError;
  99.    long   theResult;
  100.  
  101.    InitGraf( &qd.thePort );
  102.    InitFonts();
  103.    InitWindows();
  104.    InitMenus();
  105.    TEInit();
  106.    InitDialogs( 0L );
  107.    FlushEvents( everyEvent, 0 );
  108.    InitCursor();
  109.  
  110.    theError = Gestalt( gestaltQuickTime, &theResult );
  111.    if ( theError != noErr )
  112.       ExitToShell();
  113.                                                  
  114.    theError = EnterMovies();  
  115.    if ( theError != noErr )
  116.       ExitToShell(); 
  117. }
  118.  
  119.  
  120.  
  121.